h=int(input())
m=int(input())
d=int(input())
if m+int(d%60)==60:
    print(h+int(d//60)+1)
    print(m+int(d%60)-60)
    
else:
    print(h+int(d//60))
    print(m+int(d%60))